<!--
* description: 网点定义备件查询
* author: xiaochengzuan
* createdDate: 2021-3-15
-->

<template>
  <div class="app-container app-container-table">
    <one-table-template
      ref="multipleTable"
      :key="oneTableKey"
      :dynamic-buttons="tableButtons"
      :dynamic-components="tableComponents"
      :dynamic-api-config="apiConfig"
      :dynamic-table-cols="tableCols"
      :dynamic-form-fields="formField"
      :dynamic-is-show-select="false"
      :dynamic-is-init-table="true"
    />
  </div>
</template>
<script>

import { oneTableWithViewTemplateMixins } from '@/components/mixins/oneTableWithViewTemplateMixins'
import OneTableTemplate from '@/components/templates/oneTable'
import Vue from 'vue'

import { orgApis } from '@/api/pabasicdataapi'
import { exportExcel } from '@/utils/getTimeString.js'

export default {
  name: 'SiteDefinitionSparePartsQuery',

  components: {
    OneTableTemplate
    // Edit: () => import('./edit')
  },
  // 组件混入对象
  mixins: [oneTableWithViewTemplateMixins],

  // 阻塞路由预加载网格中组件的数据
  beforeRouteEnter(to, from, next) {
    Vue.prototype.$ConfigCache.CacheConfig.initData([to.path, ''], function() {
      next()
    })
  },

  data() {
    // 页面标识（与上面beforeRouteEnter中的对应）
    const viewPageCode = this.$route.path

    // 绑定事件配置化事件
    this.$ConfigCache.CacheConfig.bindEvent(this, [viewPageCode])

    return {
      editRowData: {},
      // 网格查询API配置对象
      apiConfig: orgApis.siteDefinitionSparePartsQueryquery,

      // 动态组件-按钮
      tableButtons: [
        {
          compKey: 'btnKey1',
          type: 'primary',
          size: 'small',
          name: 'search',
          clickEvent: () => this.queryTable(1),
          text: this.$t('sys.button.query'), // 查询
          position: 'right',
          fuzzySearch: true
        },
        {
          compKey: 'btnKey3',
          size: 'small',
          name: 'export',
          position: 'right',
          clickEvent: () => this.exportExcel111(), // 导出
          text: '导出'
        },
        {
          compKey: 'btnKey2',
          size: 'small',
          name: 'reset',
          clickEvent: () => this.reset(),
          text: this.$t('sys.button.reset'),
          position: 'right' // 重置
        }

      ],

      // 动态组件-查询条件
      tableComponents:
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path] &&
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path]
          .tableComponents &&
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path]
          .tableComponents.length > 0
          ? this.$ConfigCache.CacheConfig.cacheData[this.$route.path]
            .tableComponents
          : [
            {
              compKey: 'compKey3',
              labelName: '备件编码：',
              codeField: 'partNo',
              component: () => import('@/components/org/commonInput'),
              type: 'inputText',
              isMul: false,
              isMust: true
            },
            {
              compKey: 'compKey4',
              labelName: '备件名称：',
              codeField: 'partName',
              component: () => import('@/components/org/commonInput'),
              type: 'inputText',
              isMul: false,
              isMust: true
            },
            {
              compKey: 'compKey1',
              labelName: '网点编码：',
              codeField: 'dlrCode',
              component: () => import('@/components/org/commonInput'),
              type: 'inputText',
              isMul: false,
              isMust: true
            },
            {
              compKey: 'compKey2',
              labelName: '网点名称：',
              codeField: 'dlrShortName',
              component: () => import('@/components/org/commonInput'),
              type: 'inputText',
              isMul: false,
              isMust: true
            },
            {
              compKey: 'compKey5',
              labelName: '维修类型: ',
              codeField: 'partRepairType',
              textField: 'partRepairTypeName',
              customObj: {
                api: orgApis.siteDefinitionSparePartsQueryselect
              },
              component: () => import('@/components/org/commonSelect'),
              type: 'dropdownList',

              isMul: false,
              isMust: false
            },
            {
              compKey: 'compKey6',
              labelName: '修改日期：',
              codeField: 'startDate,endDate',
              component: () => import('@/components/org/datePicker/andtDatePicker'),
              type: 'YYYY-MM-DD',
              format: 'yyyy-MM-dd',
              dateOptionsType: '0',
              isMul: false,
              isMust: false
            },
            // {
            //   compKey: 'compKey7',
            //   labelName: '适用车型: ',
            //   codeField: 'carConfigIdList',
            //   component: () => import('@/components/org/carTypeConfig'),
            //   oFields: 'statusId,statusText',
            //   type: 'dropdownList',
            //   isMul: false,
            //   isMust: false
            // }
            {
              compKey: 'compKey7',
              labelName: '适用车型：',
              codeField: 'carConfigCode',
              textField: 'carConfigCn',
              component: () => import('@/views/ve/planReport/components/multipleSearchInput'),
              dataToObject: {
                oFields: 'carConfigCode,carConfigCn',
                // 控制弹窗页面 搜索 网格 元素
                tableComponents: [
                  {
                    compKey: 'compKey1',
                    labelName: '车型编码：',
                    codeField: 'carConfigCode',
                    isMul: false,
                    component: () => import('@/components/org/commonInput'),
                    type: 'inputText',
                    isMust: true,
                    span: 8
                  },
                  {
                    compKey: 'compKey2',
                    labelName: '车型名称：',
                    codeField: 'carConfigCn',
                    isMul: false,
                    component: () => import('@/components/org/commonInput'),
                    type: 'inputText',
                    isMust: true,
                    span: 8
                  }
                ],
                tableCols: [
                  {
                    prop: 'carSeriesCode',
                    label: '车系编码'
                  },
                  {
                    prop: 'carSeriesCn',
                    label: '车系名称'
                  },
                  {
                    prop: 'carConfigCode',
                    label: '车型编码'
                  },
                  {
                    prop: 'carConfigCn',
                    label: '车型名称'
                  }
                ],
                formField: {
                  carConfigCode: '',
                  carConfigCn: ''
                },
                returnField: {
                  prop: 'carConfigCode',
                  label: '车型编码'
                },
                api: { APIUrl: 'mp/e3sh/spareparts/basic/partPriceQueryService/queryCarConfigCodes.do', ServiceCode: 'queryCarConfigCodes' },
              },
              type: 'inputText',
              isMul: false,
              isMust: false
            },

          ],

      // 动态生成网格列
      tableCols:
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path] &&
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path].tableCols &&
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path].tableCols
          .length > 0
          ? this.$ConfigCache.CacheConfig.cacheData[this.$route.path].tableCols
          : [
            {
              prop: 'releaseId',
              label: '主键ID',
              hidden: true,
              alwaysHidden: true
            },
            {
              prop: 'updateControlId',
              label: '并发控制ID',
              hidden: true,
              alwaysHidden: true
            },
            {
              prop: 'dlrCode',
              label: '网点编码',
              hidden: false
            },
            {
              prop: 'dlrShortName',
              label: '网点名称',
              hidden: false
            },
            {
              prop: 'partNo',
              label: '备件编码',
              hidden: false
            },
            {
              prop: 'partName',
              label: '备件名称'
            },
            {
              prop: 'partRepairName',
              label: '维修类型'
            },
            {
              prop: 'carConfigCn',
              label: '适用车型'
            },
            {
              prop: 'isOrder',
              label: '订货开关'
            },
            {
              prop: 'outletPrice',
              label: '网点价'
            },
            {
              prop: 'userPrice',
              label: '用户价'
            },
            {
              prop: 'minSalesPage',
              label: '最小销售包装'
            },
            {
              prop: 'minPurchasePage',
              label: '最小采购包装'
            },
            {
              prop: 'unit',
              label: '备件单位'
            },
            {
              prop: 'standardStock',
              label: '安全库存'
            },
            {
              prop: 'modifyDate',
              label: '修改日期'
            },
            {
              prop: 'remark',
              label: '备注'
            }

          ],

      // 表单查询数据
      formField: this.$utils.getFormField(this, {
        dlrShortName: '',
        dlrCode: '',
        partNo: '',
        partName: '',
        partRepairType: '',
        startDate: '',
        endDate: '',
        carConfigCode: '',
        carConfigCn: '',

        updateControlId: ''
      }, this.$ConfigCache.CacheConfig.cacheData[viewPageCode])
    }
  },

  mounted() {
    // 列表查询
    this.queryTable(1)
    this.$refs['multipleTable'].list = [
      { releaseId: '1', updateControlId: '1' }
    ]
  },

  methods: {
    // 编辑获取数据
    edit(index) {
      this.editPopupsState = 'edit'
      this.editPopupsVisible = true
      this.editRowData = this.$utils.deepCopy(this.$refs['multipleTable'].list[index])
    },

    // 导出
    exportExcel111() {
      exportExcel(this.formField, orgApis.siteDefinitionSparePartsQueryexportexcel.APIUrl, orgApis.siteDefinitionSparePartsQueryexportexcel.ServiceCode, '网点备件清单维护')
    }
  }
}
</script>
